﻿using Jst.Application.Contracts.Contracts;
using Jst.Application.Contracts.Services;
using Jst.Core.Utility;
using Jst.Domain.Shared;
using Jst.Infrastructure.DbFirst;
using Jst.Infrastructure.Persistence;
using Jst.Infrastructure.Web.Authentication;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;

namespace Jst.Infrastructure.Web
{
    /// <summary>
    /// 上下文配置
    /// </summary>
    public static class HttpContextSetup
    {
        public static void AddHttpContextSetup(this IServiceCollection services)
        {
            if (services == null) throw new ArgumentNullException(nameof(services));
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            services.AddScoped<IHttpContextUser, AspNetUser>();
            var connectionConfig = new ConnectionConfig()
            {
                ConfigId = AppSettingDbEnumVars.Default_Db,
                ConnectionString = AppSettingsConstVars.DefaultConnection,
                DbType = SqlSugar.DbType.SqlServer,
                IsAutoCloseConnection = true
            };
            var sqlSugarScope = new SqlSugarScope(connectionConfig);
            services.AddSingleton<ISqlSugarClient>(_ => sqlSugarScope);
            services.AddSingleton<IDbContext, DbContext>();
            services.AddSingleton<TempDbFirstJob>();
           
        }
    }
}
